<template>
  <el-dialog v-model="dialogFormVisible" title='审核产品' width="30%" center>
    <div class="describe">确定审核此产品的出库吗？</div>
    <el-radio-group v-model="formData.product_out_status" class="ml-4">
      <el-radio label="同意" size="large">同意</el-radio>
      <el-radio label="否决" size="large">否决</el-radio>
    </el-radio-group>
    <el-input type="textarea" placeholder="请输入审核备注" v-model="formData.audit_memo" />
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="productAudit">
          确定
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { bus } from "../../../utils/mitt.js"
import { AuditProductAPI } from "../../../api/product.js"
import { ElMessage } from 'element-plus'
import { tracking } from '../../../utils/operate'

const props = defineProps<{
  GetProductApplyitList: Function,
}>()


const dialogFormVisible = ref(false)

bus.on('auditProductInfo', (row: any) => {

  formData.id = row.id
  formData.product_name = row.product_name
  formData.audit_memo = row.audit_memo
  formData.product_in_warehouse_number = row.product_in_warehouse_number
  formData.product_single_price = row.product_single_price
  formData.product_out_id = row.product_out_id
  formData.product_out_status = row.product_out_status
  formData.product_out_price = row.product_out_price
  formData.product_out_apply_person = row.product_out_apply_person
  formData.product_out_number = row.product_out_number
  formData.product_apply_time = row.product_apply_time

})

const formData = reactive({
  id: '',
  product_name: '',
  product_in_warehouse_number: '',
  product_single_price: '',
  product_out_id: '',
  product_out_status: '',
  product_out_price: '',
  product_out_apply_person: '',
  product_out_number: '',
  product_apply_time: '',
  product_out_audit_person: JSON.parse(localStorage.getItem('userinfo') as string).name,
  audit_memo: '',
})

const open = () => {
  dialogFormVisible.value = true
}

// 产品审核 
const productAudit = async () => {
  dialogFormVisible.value = false
  const res = await AuditProductAPI(formData)
  if (res.data.status == 0) {
    ElMessage({
      message: res.data.message,
      type: 'success'
    })
    props.GetProductApplyitList()
    tracking("产品管理", "审核", { name: formData.product_name, result: formData.product_out_status }, "高级")
  } else {
    ElMessage({
      message: res.data.message,
      type: 'error'
    })
  }

}

defineExpose({
  open
})
</script>